let dv=document.getElementById("dv");
let isDown=false;

let x=0;
let y=0;
//偏移量
let l=0;
let t=0;

//鼠标按下的时候
dv.onmousedown=function(e){
	var event=e || window.event;
	
	x=event.clientX;
	y=event.clientY;
	
	l=dv.offsetLeft;
	t=dv.offsetTop;
	
	isDown=true;
	dv.style.cursor="move";
};
//鼠标移动的时候
window.onmousemove=function(e){
	//鼠标松开时返回
	if(!isDown){
		return;
	}
	var event=e || window.event;
	
	//相当于你鼠标按下时的那个点就是元素的左上角，这样防止移动时发生跳跃
	var nl=event.clientX-(x-l);
	var nt=event.clientY-(y-t);
	
	dv.style.left=nl+'px';
	dv.style.top=nt+'px';
};
//鼠标松开的时候
dv.onmouseup=function(){
	isDown=false;
	dv.style.cursor="default";
};